<script setup>
    import { onUnmounted, onMounted } from 'vue'
    import { useRouter } from 'vue-router'
    import ProjectForm from './components/ProjectForm.vue'
    import ProportionForm from './components/ProportionForm.vue'
    import FacilityOverviewForm from './components/FacilityOverviewForm.vue'
    import OnlineSurveyForm from './components/OnlineSurveyForm.vue'

    const router = useRouter()

    let projectForm = $ref(null)
    let proportionForm = $ref(null)
    let overviewForm = $ref(null)
    let onlineSurveyForm = $ref(null)

    let appRef = $ref(null)

    let drawTiming = undefined

    // * 默认缩放值
    let scale = {
        width: '1',
        height: '1',
    }
 
    // * 设计稿尺寸（px）
    const baseWidth = 1920
    const baseHeight = 1080

    // * 需保持的比例（默认1.77778）
    const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5))

    onMounted(() => {
        calcRate()

        window.addEventListener('resize', resize)
    })


    const calcRate = () => {
        if (!appRef) return 
      // 当前宽高比
        const currentRate = parseFloat((window.innerWidth / window.innerHeight).toFixed(5))
        if (appRef) {
            if (currentRate > baseProportion) {
                // 表示更宽
                console.log(appRef)
                scale.width = ((window.innerHeight * baseProportion) / baseWidth).toFixed(5)
                scale.height = (window.innerHeight / baseHeight).toFixed(5)
                appRef.style.transform = `scale(${scale.width}, ${scale.height}) translateZ(0) translate3d(0, 0, 0)`
            } else {
                // 表示更高
                scale.height = ((window.innerWidth / baseProportion) / baseHeight).toFixed(5)
                scale.width = (window.innerWidth / baseWidth).toFixed(5)
                appRef.style.transform = `scale(${scale.width}, ${scale.height}) translateZ(0) translate3d(0, 0, 0)`
            }
        }
    }

    const resize = () => {
        clearTimeout(drawTiming)
        drawTiming = setTimeout(() => {
            calcRate()
        }, 200)
    }


    onUnmounted(() => {
        window.removeEventListener('resize', resize)
    })


    // 点击预览
    const handleClickPreview = () => {
        router.push('/')
    }

</script>

<template>
    <div class="data-edit-wrap">
        <div ref="appRef" class="deta-edit-main flex">
            <div class="left">
                <div class="card mb18">
                    <div class="title">项目区概况</div>
                    <ul class="list">
                        <li v-for="item in 6" :key="item"></li>
                    </ul>
                    <div class="edit-wrap">
                        <div class="edit-btn" @click="projectForm.showProjectForm()">编辑</div>
                    </div>
                </div>
    
                <div class="card">
                    <div class="title">特色农产品占比</div>
                    <ul class="list">
                        <li v-for="item in 4" :key="item"></li>
                    </ul>
                    <div class="edit-wrap">
                        <div class="edit-btn" @click="proportionForm.showProportionForm()">编辑</div>
                    </div>
                </div>
            </div>
            <div class="center">
                <div class="btn" @click="handleClickPreview">点击预览</div>
            </div>
            <div class="right">
                <div class="card">
                    <div class="title">各设备在线概况</div>
                    <ul class="list">
                        <li v-for="item in 3" :key="item"></li>
                    </ul>
                    <div class="edit-wrap">
                        <div class="edit-btn" @click="onlineSurveyForm.showOnlineForm()">编辑</div>
                    </div>
                </div>
                <div class="card mb18">
                    <div class="title">设备总览</div>
                    <ul class="list">
                        <li v-for="item in 3" :key="item"></li>
                    </ul>
                    <div class="edit-wrap">
                        <div class="edit-btn"  @click="overviewForm.showOverviewForm()">编辑</div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 项目概况编辑 -->
        <project-form ref="projectForm"></project-form>

        <!-- 特色农产品占比 编辑 -->
        <proportion-form ref="proportionForm"></proportion-form>

        <!-- 设备总览编辑 -->
        <facility-overview-form ref="overviewForm"></facility-overview-form>

        <!-- 各设备总览 编辑 -->
        <online-survey-form ref="onlineSurveyForm"></online-survey-form>

    </div>
</template>

<style lang="less" scoped>
    .data-edit-wrap{
        // width: 100%;
        // height: 100%;
        background: url('../../assets/images/zc-map.jpg') center no-repeat;
        background-size: 100% 100%;
        .deta-edit-main{
            width: 1920px;
            height: 1080px;
            padding: 98px 40px;
            // transform-origin: center center;
            // position: fixed;
        }

        .left, .right{
            width: 498px;

            &.right{
                display: flex;
                flex-direction: column-reverse; 
                align-items: flex-start;
            }

            .card{
                width: 100%;
                background: #FFFFFF;
                box-shadow: 0px -1px 61px 1px rgba(83,83,83,0.24);
                padding: 32px;

                &.mb18{
                    margin-bottom: 18px;
                }

                .title{
                    color: #333;
                    font-size: 30px;
                    font-weight: 500;
                }

                li{
                    width: 100%;
                    height: 34px;
                    background: #0054EF;
                    opacity: 0.1;
                    margin-top: 24px;

                    &:last-child{
                        width: 50%;
                    }
                }

                .edit-wrap{
                    margin-top: 17px;
                    text-align: right;

                    .edit-btn{
                        width: 90px;
                        height: 36px;
                        line-height: 36px;
                        color: #fff;
                        background: #0054EF;
                        text-align: center;
                        cursor: pointer;
                    }
                }
            }
        }

        .center{
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: flex-end;

            .btn{
                font-size: 24px;
                color: #fff;
                width: 320px;
                height: 76px;
                line-height: 76px;
                text-align: center;
                background: #0054EF;
                box-shadow: 0px 0px 23px 1px rgba(83,83,83,0.44);
                cursor: pointer;
            }
        }
    }
</style>

<style lang="less">
    .form-dialog{

        .el-select .el-input__wrapper, .el-input .el-input__wrapper{
            background: transparent;
            /* border-color: #1C4EB0; */
            box-shadow: 0 0 0 1px var(--el-input-border-color,var(--el-border-color)) inset;

            .el-input__inner{
                color: #333 !important;
            }
        }


        .form-item{
            padding: 20px;

            .form-row{
                display: inline-block;
                width: 50%;
                padding-left: 10px;
                padding-bottom: 24px;
                
                .title{
                    padding-bottom: 10px;
                }

                .input-wrap{
                    display: flex;
                    align-items: center;
                    
                    .el-input-number{
                        width: 300px;
                    }

                    span.label{
                        margin-left: 5px;
                    }
                    .row-count-2{
                        margin-right: 10px;
                        .el-input-number{
                            width: 108px
                        }
                    }
                }
            }
        }

        .tips{
            color: #FC0000;
            font-size: 12px;
            margin-left: 20px;
        }
    }
</style>